package repository

import (
	 "gopkg.in/mgo.v2"
	"time"
)

type DataStore struct {
	S *mgo.Session
}

var DS DataStore

func (ds DataStore) DataStore() *DataStore {
	return &DataStore{ds.S.Copy()}
}

func DBConnect() bool {
	mongoDBDialInfo := &mgo.DialInfo{
		Addrs:    []string{"39.98.39.186:8500"},
		Timeout:  time.Duration(5000) * time.Millisecond,
		Database: "edgex-club",
		Username: "",
		Password: "",
	}
	s, err := mgo.DialWithInfo(mongoDBDialInfo)
	if err != nil {
		return false
	}
	s.SetSocketTimeout(time.Duration(5000) * time.Millisecond)
	DS.S = s
	return true
}
